﻿@model IEnumerable<Client>
@{
    ViewBag.Title = EntityNames.Client;
    ViewBag.PageTitle = ViewBag.Title + "_内容";
    Layout = "~/Areas/Admin/Views/Shared/_Layout.cshtml";
}


<div class="panel panel-default">
    <header class="panel-heading">
        <span class="glyphicon glyphicon-file"></span> @ViewBag.Title
    </header>

    <section class="panel-body">
        <div class="text-right">
            <a class="btn btn-primary" href="@Url.Action("Add")"><i class="glyphicon glyphicon-plus"></i> @string.Format("{0}{1}", Buttons.Add, EntityNames.Client)</a>
            <a class="btn btn-default" href="@Url.Action("AddWork","Work")"><i class="glyphicon glyphicon-plus"></i> @string.Format("{0}{1}", Buttons.Add, EntityNames.Work)</a>
        </div>
    </section>

    <div class="table-responsive">
        <table class="table table-hover table-vmiddle">
            <thead>
                <tr>
                    <th>
                        Logo  
                    </th>
                    <th>
                        主题
                    </th>
                    <th>
                        主页
                    </th>
                    <th>
                        <span class="glyphicon glyphicon-user"></span> 发布者
                    </th>
                    <th>
                        <span class="glyphicon glyphicon-time"></span> 创建日期
                    </th>
                    <th>
                        操作
                    </th>
                </tr>
            </thead>
            <tbody>
                @foreach (var item in Model)
                {
                    <tr class="first">
                        <td>
                          @if (!string.IsNullOrEmpty(item.LogoURL))
                          {
                            <img src="@string.Format("{0}?w=100&mode=Crop",  item.LogoURL)" alt="@item.ClientName" />
                          }                      
                        </td>
                        <td>
                            @item.ClientName
                        </td>
                        <td>
                            <a href="@item.Homepage" target="_blank">@item.Homepage</a>
                        </td>
                        <td>
                            @item.AddedBy
                        </td>
                        <td>@item.AddedDate.ToShortDateString()</td>
                        <td>
                            <a href="@Url.Action("Edit", new { Id = item.Id })" class="btn btn-xs btn-primary"><i class="glyphicon glyphicon-edit"></i></a>
                            <a href="@Url.Action("Delete", new { Id = item.Id })" class="btn btn-xs btn-danger delete-type"><i class="glyphicon glyphicon-trash"></i></a>
                        </td>
                    </tr>
                }

            </tbody>

        </table>



    </div>


    <footer class="panel-footer"></footer>


</div>

<!-- end main container -->
@section footer {

    <script>

        $(function () {

            //删除数据
            $('.delete-type')
                .click(function (e) {
                    var url = $(this).attr('href');
                    var that = $(this);

                    var title = '@string.Format("删除{0}",EntityNames.Client)';
                    // console.log(url);
                    /*DELETE*/
                    $.ajax({
                        url: url,
                        dataType: "json",
                        type: "POST",
                        contentType: 'application/json; charset=utf-8',
                        data: JSON.stringify({}),
                        async: true,
                        processData: false,
                        cache: false,
                        success: function (data) {

                            Common.ShowBox(data.Status, data.Message, title);

                            if (data.Status === 1) {
                                that.closest('tr').remove();
                            }

                        },
                        error: function (xhr) {
                            toastr.error('@Messages.AlertDeleteFailure', title);
                        }
                    });

                    e.preventDefault();
                });

        });
    </script>

}